package cn.yeziji.forum.dao.iquery;

import cn.org.atool.fluent.mybatis.base.crud.JoinBuilder;
import cn.org.atool.fluent.mybatis.segment.JoinQuery;
import cn.yeziji.forum.common.Paging;
import cn.yeziji.forum.wrapper.ForumFeedbackQuery;
import cn.yeziji.forum.wrapper.ForumUserQuery;

/**
 * 反馈查询
 *
 * @author gzkemays
 * @since 2022/11/05 7:03 PM
 */
public class FeedbackQuery {
  /**
   * 获取用户以及反馈信息
   *
   * @return 查询条件
   */
  public static JoinQuery findUserFeedbackListQuery() {
    return JoinBuilder.from(
            new ForumFeedbackQuery().select.createTime("`date`").and.title().and.content().end())
        .leftJoin(new ForumUserQuery().select.nickname("username").and.avatar().end())
        .on(l -> l.where.userId(), r -> r.where.id())
        .endJoin()
        .build();
  }

  /**
   * 用户以及反馈信息的分页查询
   *
   * @param paging 分页
   */
  public static JoinQuery findUserFeedbackPagingQuery(Paging paging) {
    return findUserFeedbackListQuery().limit(paging.prefix(), paging.last());
  }
}
